package com.itheima.springbootconfig.controller;

import com.itheima.springbootconfig.pojo.person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloApplication {
    //获取普通配置
    @Value("${name}")
    private String name;
    //获取对象属性
    @Value("${person.name}")
    private String name2;
    //获取数组
    @Value("${address[0]}")
    private String address1;

    //获取纯量
    @Value("${msg1}")
    private String msg1;
    @Autowired
    private Environment env;
    @Autowired
    private person person;

    @RequestMapping("/hello")
    public String hello() {
        return " hello Spring Boot !";
    }

    @RequestMapping("/get1")
    public String get1() {
        return env.getProperty("person.name");
    }

    @RequestMapping("/get2")
    public String get2() {
        return env.getProperty("address[0]");
    }

    @RequestMapping("/get3")
    public String get3() {
        return name;
    }

    @RequestMapping("/get4")
    public person get4() {
        String[] address = person.getAddress();
        for (String s : address) {
            System.out.println(s);
        }
        return person;
    }
}
